import  cv2 as cv


imgPath = "lena.jpg"
img = cv.imread(imgPath);
# 题目二, 代码如下
cv.imshow("HelloWorld",img)

gray=cv.cvtColor(img,cv.COLOR_BGR2GRAY)
cv.imshow("Gray",gray)
#题目三, 代码如下

# RGB分量显示
cv.imshow("B",img[:,:,0])
cv.imshow("G",img[:,:,1])
cv.imshow("R",img[:,:,2])
# HSI分量显示
out_img_HSV=cv.cvtColor(img,cv.COLOR_BGR2HSV)
hsvChannels=cv.split(out_img_HSV)  #将HSV格式的图片分解为3个通道

cv.imshow('H',hsvChannels[0]) #显示Hue分量
cv.imshow('S',hsvChannels[1]) #显示Saturation分量
cv.imshow('V',hsvChannels[2]) #显示Value分量

cv.moveWindow("HelloWorld",0,40)
cv.moveWindow("Gray",0,600)

cv.moveWindow("R",550,40)
cv.moveWindow("G",1100,40)
cv.moveWindow("B",1650,40)

cv.moveWindow("H",550,600)
cv.moveWindow("S",1100,600)
cv.moveWindow("V",1650,600)
cv.waitKey()
cv.destroyAllWindows()

